﻿using System;
using System.Runtime.InteropServices;
using Demo.Main.ApplicationStart;
using wd2now.Framework.Builder;
using wd2now.Framework.Controller;
using wd2now.Framework.Legacy.Classes;
using wd2now.Model.Actions;

namespace Demo.Main
{
    public class MainController
    {
        protected TableController Controller;
        protected TableBuilder Builder;

        public MainController(IntPtr getSymbolFromDll, IntPtr getPlayerName)
        {
            Controller = new TableController();
            Builder = new TableBuilder(getSymbolFromDll, getPlayerName);

            var bootStrapper = new BootStrapper();
            bootStrapper.Initialize(Controller);
        }

        public double ProcessQuery(string pquery)
        {
            var table = Builder.BuildTable();

            switch (pquery)
            {
                case "dll$swag":
                    var action = Controller.Play(table);
                    if (action.Type == ActionType.BetRaise)
                    {
                        return action.Amount;
                    }
                    break;

                case "dll$call":
                    var action2 = Controller.Play(table);
                    if (action2.Type == ActionType.Call)
                    {
                        return 1;
                    }
                    break;
            }
            return 0;
        }

        public static void UpdateState(IntPtr s)
        {
            TableBuilder.mhs = (managed_holdem_state)Marshal.PtrToStructure(s, typeof(managed_holdem_state));
        }


    }
}
